package com.springboot.controller;

import com.springboot.bean.ChatMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * @author zz
 * @version 1.0
 * @Description
 */
@Controller
public class ChatController {

    // 处理客户端发送到 /app/sendMessage 的消息
    @MessageMapping("/sendMessage")
    // 将处理后的消息发送到 /topic/public 主题，订阅该主题的客户端都能收到消息
    @SendTo("/topic/public")
    public ChatMessage sendMessage(ChatMessage chatMessage) {
        return chatMessage;
    }
}